//
//  MinePurchaseRecordTableViewCell.swift
//  MT
//
//  Created by M on 2019/12/31.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import MTCategory

class MinePurchaseRecordTableViewCell: UITableViewCell {
    
    var model: MinePurchaseRecordModel? {
        didSet {
            guard let model = model else { return }
            if let purchaseType = MinePurchaseRecordModel.PurchaseType(rawValue: model.purchaseType) {
                titleLabel.text = purchaseType.title
                priceLabel.text = "\(purchaseType.status == .expense ? "-" : "+")" + "\(model.amount)" + " \(purchaseType.status == .receive ? "钻石" : "")"
                priceLabel.textColor = purchaseType.status == .receive ? UIColor(hex: 0xfd387c) : UIColor.theme.main
            } else {
                titleLabel.text = nil
            }
            dateLabel.text = model.createTime
        }
    }
    
    /// Title Label
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = PingFangSCRegularFont(18)
        label.textColor = .white
        label.textAlignment = .left
        return label
    }()
    
    /// Date Label
    lazy var dateLabel: UILabel = {
        let label = UILabel()
        label.font = PingFangSCRegularFont(12)
        label.textColor = .white
        label.textAlignment = .left
        return label
    }()
    
    /// Price
    lazy var priceLabel: UILabel = {
        let label = UILabel()
        label.font = PingFangSCSemiboldFont(18)
        label.textColor = .white
        label.textAlignment = .left
        return label
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initializeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

// MARK: ------------------------------------ 初始化 ----------------------------------------
extension MinePurchaseRecordTableViewCell {
    
    private func initializeUI() {
        contentView.backgroundColor = UIColor(hex: 0x161616)
        contentView.addSubview(titleLabel)
        contentView.addSubview(dateLabel)
        contentView.addSubview(priceLabel)
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(contentView).offset(16)
            make.top.equalTo(contentView).offset(24)
        }
        
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(3)
        }
        
        priceLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel)
            make.right.equalTo(contentView).offset(-16)
        }
    }
    
}
